<template>
	<div class="me">
		<div class="title">
			<span>我的</span>
		</div>
		<div class="userInfo">
			<img class="userHead" src="../../assets/imgs/user.png"/>
			<p class="userName">
				<span>{{username}}</span>
				<span>{{userInfo.role}}</span>
			</p>
		</div>
		<div class="myWork">
			<div class="dot">{{allInfo.length}}</div>
			<!-- <h6>我的任务</h6> -->
			<div class="workItem">
				
				<div class="unfinish" @click="goUnfinish">
					<img class="workImg" src="../../assets/imgs/unFinish1.png" width="100%" />
					<span>未完成</span>
				</div>
				<div class="finish" @click="goFinish">
					<img class="workImg" src="../../assets/imgs/finish.png" width="100%" />
					<span>已完成</span>
				</div>
			</div>
		</div>
		<van-cell-group>
			<van-cell>
				<div class="line">
					<img src="../../assets/imgs/role.png" />
					<span>{{username}}</span>
				</div>
			</van-cell>
			<van-cell is-link="" :center='true'>
				<div class="line">
					<img src="../../assets/imgs/problem.png" />
					<span>帮助中心</span>
				</div>
			</van-cell>
			<van-cell is-link="" :center="true" @click='goSetCenter'>
				<div class="line">
					<img src="../../assets/imgs/set.png" />
					<span>设置中心</span>
				</div>
			</van-cell>
			<van-cell is-link="" :center="true">
				<div class="line">
					<img src="../../assets/imgs/update.png" />
					<span>检测更新</span>
				</div>
			</van-cell>
		</van-cell-group>
		<div class="btn">
			<van-button type="default" size="large" @click='exit'>退出登录</van-button>
		</div>
		
	</div>
</template>

<script>
	export default{
		data(){
			return{
				userInfo:{},
				allInfo:[],
				username:''
			}
		},
		created() {
			this.getUserInfo()
			this.getAllInfo()
			this.username = JSON.parse(localStorage.cksLoginInfo).userName
		},
		methods:{
			getAllInfo(){
				this.$axios.post('/Maintenance/selectAllMaintenance.do').then(res=>{
					if(res.data.status===200){
						let newData = res.data.msg
						let userName = JSON.parse(localStorage.cksLoginInfo).userName
						let userId = JSON.parse(localStorage.cksLoginInfo).id
						newData.map((value,index)=>{
							if(value.state === 2&&(value.maintenanceuserid == userId||value.maintanceusername == userName)){
								this.allInfo.push(value)
							}
						})
						
					}
				console.log(this.allInfo);
					
				})
			},
			getUserInfo(){
				this.$axios.post(this.url.searchUser,{number:JSON.parse(localStorage.cksLoginInfo).id,name:''}).then(res=>{
					if(res.data.status === 200){
						
						this.userInfo.role = res.data.data[0].rolename
						this.userInfo.depart = res.data.dep[0].name
						this.$forceUpdate()
					}
				})
			},
			/* getLoginUserInfo(){
				this.$axios.post('http://121.41.32.143:8080/JQ-DCP/User/getCurrentUser.do').then(res=>{
					this.userInfo = res.data.currentUser
					this.getUserInfo()
				})
			}, */
			exit(){
				this.$router.push({name:'login'})
				localStorage.cksLoginInfo = ''
			},
			goUnfinish(){
        this.$router.push({name:'unfinish'})//未完成维修
				/* if(this.userInfo.role === '维修员'){
					
				}else if(this.userInfo.role === '保养员'){
					this.$router.push({name:'maintainUnfinish'})//未完成保养
				} */
			},
			goFinish(){
        this.$router.push({name:'repairdeviceList',params:{isMe:true}})//完成维修
				/* if(this.userInfo.role === '维修员'){
					
				}else if(this.userInfo.role === '保养员'){
					this.$router.push({name:'deviceKeep',params:{display:false}})//完成保养
				} */
			},
			goSetCenter(){
				this.$router.push({name:'setCenter'})
			}
		}
	}
</script>

<style scoped="scoped">
	.dot{
		width: .8rem;
		height: .8rem;
		text-align: center;
		background: red;
		font-size: .6rem;
		color: white;
		left: 7.1rem;
		margin-top: .3rem;
		position: absolute;
		border-radius: 50%;
		-moz-box-shadow:2px 2px 2px #C4C4C4; -webkit-box-shadow:2px 2px 2px #C4C4C4; box-shadow:2px 2px 2px #C4C4C4;
	}
	.van-button{
		margin-top: .8rem;
		background: ghostwhite;
	}
	.line{
		font-size: .8rem;
		color: #666;
	}
	.line img{
		margin-right: .6rem;
		vertical-align: middle;
		height: 1.37rem;
	}
	.workImg{
		width: 1rem;
		height: 1rem;
		vertical-align: middle;
	}
	.workItem{
		display: flex;
		padding: 1rem;
	}
	.workItem div{
		flex: 1;
		text-align: center;
		color: #999999;
		font-size: .78rem;
	}
	.workItem div:first-child{
		border-right: 1px solid #EEEEEE;
	}
	.myWork{
		border-bottom: .7rem solid whitesmoke;
	}
	h6{
		margin: 0;
		font-size: .85rem;
	}
	.title{
		text-align: center;
		height: 3rem;
		line-height: 3rem;
		font-size: .9rem;
		color: white;
	}
	.title,.userInfo{
		background: #62cff9;
	}
	.userInfo{
		text-align: center;
	}
	.userName{
		color: white;
		padding-bottom: 1rem;
		font-size: .8rem;
	}
	.userName span:first-child{
		padding-right: .5rem;
		/* border-right: 1px solid #EEEEEE; */
	}
	.userName span:last-child{
		padding-left: .5rem;
	}
	.userHead{
		width: 3.5rem;
		height: 3.5rem;
		object-fit: contain;
		border-radius: 50%;
		background: white;
	}
	.van-button--large {
		height: 2.3rem;
		line-height: 2.3rem;
		margin-bottom: .7rem;
	}
	.btn{
		padding: .8rem;
		border-radius: 15px;
	}
</style>
